package org.ytor.core.querygen;

import org.springframework.core.Ordered;
import org.ytor.core.querygen.token.Token;
import org.ytor.core.sqlflow.builder.support.WhereBuilder;

/**
 * created by yangtong on 2025/8/11 14:06:58
 * <br/>
 * 抽象的条件解释器
 */
public abstract class AbsWhere implements Ordered {
    /**
     * 判断当前解释器是否支持该 TOKEN
     */
    public abstract Boolean isMatch(Token token);

    /**
     * 将 TOKEN 拼接到WhereBuilder
     */
    public abstract WhereBuilder apply(WhereBuilder where, Token token);

    /**
     * 正、逆逻辑分发
     */
    protected WhereBuilder positiveOrNegate(WhereBuilder where, Token token) {
        return token.isPositive() ? positive(where, token) : negate(where, token);
    }

    /**
     * 正向匹配（如 =、>、IN、LIKE 等）
     */
    protected abstract WhereBuilder positive(WhereBuilder where, Token token);

    /**
     * 逆向匹配（如 !=、NOT IN、NOT LIKE…）
     */
    protected abstract WhereBuilder negate(WhereBuilder where, Token token);
}
